home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGBLER / ASMCODE2.LZH / MACRO.ASM < prev    next >
Assembly Source File  |  1985-05-19  |  16KB  |  607 lines

  1. ;-----------------------------------------------------------------------
  2. ;
  3. ;  Assembly Language Macros  Version 0.1
  4. ;  Written by: Malcolm McCorquodale III  Houston, Texas  713-626-4979
  5. ;
  6. ;  (c) 1984 by Malcolm McCorquodale III  All commercial rights reserved.
  7. ;
  8. ;  This software is distributed using the "FREE-SOFTWARE" concept.
  9. ;  If you find these macros useful send whatever contribution you
  10. ;  deem appropriate to:
  11. ;
  12. ;         Malcolm McCorquodale III
  13. ;         3470 Locke Lane,
  14. ;         Houston Texas 77027.
  15. ;         (713) 626 - 4979
  16. ;
  17. ;-----------------------------------------------------------------------
  18.  
  19. ;;-----------------------------------------------------------------------
  20. ;;
  21. ;;     General Purpose Macros
  22. ;;
  23. ;;-----------------------------------------------------------------------
  24.  
  25. ;;-----------------------------------------------------------------------
  26. ;;
  27. ;; SAVE <p1,..,p8>  Pushes 1 to 8 parameters.
  28. ;;            Parameters p2 through p8 are optional.
  29. ;;
  30. ;;-----------------------------------------------------------------------
  31. SAVE    MACRO    P1,P2,P3,P4,P5,P6,P7,P8
  32.     IRP    X,<P1,P2,P3,P4,P5,P6,P7,P8>
  33. IFNB    <X>
  34.     PUSH   X
  35. ENDIF
  36.     ENDM
  37.     ENDM
  38.  
  39. ;;-----------------------------------------------------------------------
  40. ;;
  41. ;; RESTORE <p1,..,p8>  Pops 1 to 8 parameters.
  42. ;;               Parameters p2 through p8 are optional.
  43. ;;
  44. ;;-----------------------------------------------------------------------
  45. RESTORE MACRO    P1,P2,P3,P4,P5,P6,P7,P8
  46.     IRP    X,<P1,P2,P3,P4,P5,P6,P7,P8>
  47. IFNB    <X>
  48.     POP    X
  49. ENDIF
  50.     ENDM
  51.     ENDM
  52.  
  53. ;;-----------------------------------------------------------------------
  54. ;;
  55. ;; PRINT <msg> - Writes msg on the screen.
  56. ;;
  57. ;;         No registers destroyed.
  58. ;;
  59. ;;-----------------------------------------------------------------------
  60. PRINT    MACRO    MSG        ; Print message on the screen.
  61.     LOCAL    TEXT,PEXIT
  62.     SAVE    DS,DX
  63.     MOV    DX,CS
  64.     MOV    DS,DX
  65.     MOV    DX,OFFSET TEXT
  66.     MOV    AH,9
  67.     INT    21H
  68.     RESTORE DX,DS
  69.     JMP    PEXIT
  70. TEXT    DB    MSG,'$'
  71. PEXIT:
  72.     ENDM
  73.  
  74. ;;-----------------------------------------------------------------------
  75. ;;
  76. ;; The macros below this point have not been fully tested.  MM.
  77. ;;
  78. ;;-----------------------------------------------------------------------
  79. ;;-----------------------------------------------------------------------
  80. ;;
  81. ;; TERMINATE - End program and return to caller.
  82. ;;
  83. ;;-----------------------------------------------------------------------
  84. TERMINATE MACRO         ; End of program.
  85.       INT      20H
  86.       ENDM
  87.  
  88. ;;-----------------------------------------------------------------------
  89. ;;
  90. ;; RWABS <rw>,<drive>,<nofsect>,<beg>
  91. ;;     <rw>       - 'R' for read, 'W' for write.
  92. ;;     <drive>   - drive number.
  93. ;;     <nofsect> - number of sectors to transfer.
  94. ;;     <beg>       - Begining logical sector number.
  95. ;;
  96. ;;     Read and write absolute sectors.
  97. ;;
  98. ;;     Note: 1) Status information is returned in flags, After the
  99. ;;          flags are sampled they should be poped off the stack
  100. ;;          with a POPF.
  101. ;;
  102. ;;           2) DS:DX must point to the DTA before this call.
  103. ;;
  104. ;;-----------------------------------------------------------------------
  105. RWABS    MACRO    RW,DRIVE,NOFSECT,BEG    ; R/W absolute disk sector.
  106.     SAVE    BX,CX,DX
  107.     MOV    AL,DRIVE
  108.     MOV    CX,NOFSECT
  109.     MOV    DX,BEG
  110. IFIDN    <RW>,<'R'>
  111.     INT    25H
  112. ENDIF
  113. IFIDN    <RW>,<'W'>
  114.     INT    26H
  115. ENDIF
  116.     RESTORE DX,CX,BX
  117.     ENDM
  118.  
  119. ;;-----------------------------------------------------------------------
  120. ;;
  121. ;; ADDTODOS <dosend> - Add the current proc to DOS.
  122. ;;
  123. ;;        Note: <dosend> is a label at the highest memory address
  124. ;;          used by your code.
  125. ;;
  126. ;;-----------------------------------------------------------------------
  127. ADDTODOS MACRO    DOSEND        ; Add a procedure to DOS.
  128.     MOV    DX,DOSEND
  129.     INC    DX
  130.     INT    27H
  131.     ENDM
  132.  
  133. ;;-----------------------------------------------------------------------
  134. ;;
  135. ;; DOSRS232 <char>
  136. ;;        Sends or receives a <char> to/from the standard RS232 port.
  137. ;;
  138. ;;        If <char> is specified then it is sent to the RS232 port.
  139. ;;        If <char> is not specified then a character is read into AL.
  140. ;;
  141. ;;        OUTPUT: If receiving data AL will contain the byte received.
  142. ;;
  143. ;;        All registers saved.
  144. ;;
  145. ;;-----------------------------------------------------------------------
  146. DOSRS232 MACRO    CHAR
  147.     SAVE    AH,DL
  148. IFB    <CHAR>
  149.     MOV    AH,3    ; Receive a character from the RS232 port.
  150. ELSE
  151.     MOV    AH,4    ; Send a character to the RS232 port.
  152. ENDIF
  153.     INT    21H
  154.     RESTORE DL,AH
  155.     ENDM
  156.  
  157. ;;-----------------------------------------------------------------------
  158. ;;
  159. ;; PRINT1 <char> - Send <char> to the standard printer.
  160. ;;
  161. ;;           No registers destroyed.
  162. ;;
  163. ;;-----------------------------------------------------------------------
  164. PRINT1    MACRO    CHAR        ; Send a character to the printer.
  165.     SAVE    AH,DL
  166.     MOV    DL,CHAR
  167.     MOV    AH,5
  168.     INT    21H
  169.     RESTORE DL,AH
  170.     ENDM
  171.  
  172. ;;-----------------------------------------------------------------------
  173. ;;
  174. ;; INPUTSTR <len>,<bufoff>,[<bufseg>]
  175. ;;        <len> - Length of input buffer.
  176. ;;        <bufoff> - Offset from <bufseg> to message buffer.
  177. ;;        <bufseg> - Optional segment for input buffer.
  178. ;;
  179. ;;        Input a string ending with a RETURN from the standard
  180. ;;        input device.
  181. ;;
  182. ;;        No registers destroyed except DS:DX which points to
  183. ;;        input buffer on output.
  184. ;;
  185. ;;        On exit: DS:DX will have <bufseg>:<bufoff>.
  186. ;;             Byte 1 of buffer = Size of buffer.
  187. ;;             Byte 2 of buffer = Number of bytes read w/o c/r.
  188. ;;             Byte 3 of buffer = Start of text read.
  189. ;;
  190. ;;-----------------------------------------------------------------------
  191. INPUTSTR MACRO    LEN,BUFOFF,BUFSEG    ; Get a line of text.
  192.     PUSH    AH
  193. IFNB    <BUFSEG>
  194.     MOV    DX,BUFSEG
  195.     MOV    DS,DX
  196. ENDIF
  197.     MOV    DX,BUFOFF
  198.     MOV    [DX],LEN
  199.     MOV    AH,0AH
  200.     INT    21H
  201.     POP    AH
  202.     ENDM
  203.  
  204. ;;-----------------------------------------------------------------------
  205. ;;
  206. ;; POLLSTDIN - Check the status of the standard input device.
  207. ;;
  208. ;;           On exit: AL = 0FFH - Character is available.
  209. ;;                  00H - Character not available.
  210. ;;
  211. ;;           Note: This routine executes an INT 23H if a ctl-brk
  212. ;;             is detected.
  213. ;;
  214. ;;           No registesrs destroyed.
  215. ;;
  216. ;;-----------------------------------------------------------------------
  217. POLLSTDIN MACRO         ; Poll the standard input device.
  218.     PUSH    AH
  219.     MOV    AH,0BH
  220.     INT    21H
  221.     POP    AH
  222.     ENDM
  223.  
  224. ;;-----------------------------------------------------------------------
  225. ;;
  226. ;; CLRSTDIN <func> - Clear standard input buffer then execute
  227. ;;             function <func>.
  228. ;;        <func> may be 1 - Keyboard input.
  229. ;;              6 - Direct Console I/O.
  230. ;;              7 - Direct Console Input w/o Echo.
  231. ;;              8 - Console Input w/o Echo.
  232. ;;              A - Buffered Keyboard Input.
  233. ;;
  234. ;;        No registers destroyed except AX.
  235. ;;
  236. ;;-----------------------------------------------------------------------
  237. CLRSTDIN MACRO    FUNC        ; Clear the standard input device.
  238.     MOV    AL,FUNC
  239.     MOV    AH,0CH
  240.     INT    21H
  241.     ENDM
  242.  
  243. ;;-----------------------------------------------------------------------
  244. ;;
  245. ;; DISKRESET - Flushes all file buffers.
  246. ;;
  247. ;;-----------------------------------------------------------------------
  248. DISKRESET MACRO         ; Reset the disk.
  249.     PUSH    AH
  250.     MOV    AH,0DH
  251.     INT    21H
  252.     POP    AH
  253.     ENDM
  254.  
  255. ;;-----------------------------------------------------------------------
  256. ;;
  257. ;; PICKDRIVE  <drive> - Select the default disk drive.
  258. ;;
  259. ;;            Input: 0 = Drive A, 1 = Drive B, etc.
  260. ;;
  261. ;;            Output: AL = number of drives. Minimum=2.
  262. ;;
  263. ;;            No registers destroyed.
  264. ;;
  265. ;;-----------------------------------------------------------------------
  266. PICKDRIVE MACRO DRIVE        ; Pick the default disk drive.
  267.     SAVE    DL,AH
  268.     MOV    DL,DRIVE
  269.     MOV    AH,0EH
  270.     INT    21H
  271.     RESTORE AH,DL
  272.     ENDM
  273.  
  274. ;;-----------------------------------------------------------------------
  275. ;;
  276. ;; FINDRIVE - Determine the default drive.
  277. ;;
  278. ;;          Output: AL = 0 = Drive A, 1 = Drive B, etc.
  279. ;;
  280. ;;          No registers destroyed except AL.
  281. ;;
  282. ;;-----------------------------------------------------------------------
  283. FINDRIVE MACRO            ; Find the default disk drive.
  284.     PUSH    AH
  285.     MOV    AH,19H
  286.     INT    21H
  287.     POP    AH
  288.     ENDM
  289.  
  290. ;;-----------------------------------------------------------------------
  291. ;;
  292. ;; SETDTA - Set the DTA.
  293. ;;
  294. ;;        On input: DS:DX must point to new DTA.
  295. ;;
  296. ;;-----------------------------------------------------------------------
  297. SETDTA    MACRO            ; Set the DTA.
  298.     PUSH    AH
  299.     MOV    AH,1AH
  300.     INT    21H
  301.     POP    AH
  302.     ENDM
  303.  
  304. ;;-----------------------------------------------------------------------
  305. ;;
  306. ;; ALLOCTAB <drive> - Get pointer to FAT ID byte.
  307. ;;
  308. ;;        If <drive> is specified then the pointer to the FAT ID
  309. ;;               for drive <drive> is returned.
  310. ;;        If <drive> is not specified then a pointer to the FAT ID
  311. ;;               byte for the default drive is returned.
  312. ;;
  313. ;;        Output: [DS:BX] = FAT ID byte.
  314. ;;            DX        = Number of allocation units.
  315. ;;            AL        = Number of sectors per allocation unit.
  316. ;;            CX        = Size of the physical sector.
  317. ;;
  318. ;;-----------------------------------------------------------------------
  319. ALLOCTAB MACRO    DRIVE
  320.     PUSH    AH
  321. IFB    <DRIVE>
  322.     MOV    AH,1BH        ; Get FAT ID for default drive.
  323. ELSE
  324.     MOV    AH,1CH        ; Get FAT ID for specified drive.
  325.     MOV    DL,DRIVE
  326. ENDIF
  327.     INT    21H
  328.     POP    AH
  329.     ENDM
  330.  
  331. ;;-----------------------------------------------------------------------
  332. ;;
  333. ;; CHANGEINT <int>,<seg>,<off> - If <seg> and <off> are specified then
  334. ;;         interupt vector <int> is set to <seg>:<off>. If <seg> and
  335. ;;         <off> are not specified then interupt vector <int> is
  336. ;;         returned in ES:BX.
  337. ;;
  338. ;;         All registers saved except ES and BX when a GET VECTOR
  339. ;;-----------------------------------------------------------------------
  340. CHANGEINT MACRO INT,SEG,OFF
  341.     PUSH    AX
  342.     MOV    AL,INT
  343. IFNB    <SEG>
  344.     MOV    AH,25H        ; Set interupt vector.
  345.     MOV    DX,SEG
  346.     MOV    DS,DX
  347.     MOV    DX,OFF
  348. ELSE
  349.     MOV    AH,35H        ; Get interupt vector.
  350. ENDIF
  351.     INT    21H
  352.     POP    AX
  353.     ENDM
  354.  
  355. ;;-----------------------------------------------------------------------
  356. ;;
  357. ;; GETDATE - Return the date in CX:DX. CX has the year (1980-2099) in bi
  358. ;;         in binary. DH has the month (1-0C). DL has the day.
  359. ;;         All registers preserved
  360. ;;
  361. ;;-----------------------------------------------------------------------
  362. GETDATE MACRO            ; Get the date.
  363.     PUSH    AH
  364.     MOV    AH,2AH
  365.     INT    21H
  366.     POP    AH
  367.     ENDM
  368.  
  369. ;;-----------------------------------------------------------------------
  370. ;;
  371. ;; SETDATE <yr>,<mo>,<day> - Set the date. <yr> is 1980..2099.
  372. ;;       <mo> is 1..0CH. <day> is 1..31. On return: AL = 00 = sucess
  373. ;;       AL = 0FFH = failure.
  374. ;;
  375. ;;-----------------------------------------------------------------------
  376. SETDATE MACRO YR,MO,DAY     ; Set the date.
  377.     SAVE    CX,DX,AH
  378.     MOV    AH,2BH
  379.     MOV    CX,YR
  380.     MOV    DH,MO
  381.     MOV    DL,DAY
  382.     INT    21H
  383.     RESTORE AH,DX,CX
  384.     ENDM
  385.  
  386. ;;-----------------------------------------------------------------------
  387. ;;
  388. ;; GETTIME - Get the time of day. Returns CX:DX. CH = hours (0..23),
  389. ;;         CL = minutes (0..59), DH = seconds (0..59), DL = 1/100
  390. ;;         seconds (0..99).
  391. ;;
  392. ;;-----------------------------------------------------------------------
  393. GETTIME MACRO            ; Get the time.
  394.     PUSH    AH
  395.     MOV    AH,2CH
  396.     INT    21H
  397.     POP    AH
  398.     ENDM
  399.  
  400. ;;-----------------------------------------------------------------------
  401. ;;
  402. ;; SETTIME <hr>,<min>,<sec>,<sec100> - Set the time.
  403. ;;
  404. ;;-----------------------------------------------------------------------
  405. SETTIME MACRO    HR,MIN,SEC,SEC100    ; Set the time.
  406.     SAVE    CX,DX,AH
  407.     MOV    AH,2D
  408.     MOV    CH,HR
  409.     MOV    CL,MIN
  410.     MOV    DH,SEC
  411.     MOV    DL,SEC100
  412.     INT    21H
  413.     RESTORE AH,DX,CX
  414.     ENDM
  415.  
  416. ;;-----------------------------------------------------------------------
  417. ;;
  418. ;; VERIFY <flag> - Set or reset the verify flag.
  419. ;;
  420. ;;      <flag> may be either 'ON', 'OFF' or 'QUERY'.
  421. ;;         For 'OFF' and 'ON' all regs are
  422. ;;         saved.  For 'QUERY' AL returns 00 if off, 01 if on.
  423. ;;
  424. ;;       OUTPUT: If <flag> is 'QUERY' then: AL = 0 for verify off
  425. ;;                           1 for verify on
  426. ;;       All registers saved if <flag> is not 'QUERY' else AL destroyed.
  427. ;;
  428. ;;-----------------------------------------------------------------------
  429. VERIFY    MACRO    FLAG
  430. IFIDN    <FLAG>,<'OFF'>  ; TURN VERIFY SWITCH OFF.
  431.     SAVE    AX,DL
  432.     XOR    DL,DL
  433.     XOR    AL,AL
  434.     MOV    AH,2EH
  435.     INT    21H
  436.     RESTORE DL,AX
  437. ENDIF
  438. IFIDN    <FLAG>,<'ON'>   ; TURN VERIFY SWITCH ON.
  439.     SAVE    AX,DL
  440.     XOR    DL,DL
  441.     MOV    AL,1
  442.     MOV    AH,2EH
  443.     INT    21H
  444.     RESTORE DL,AX
  445. ENDIF
  446. IFIDN    <FLAG>,<'QUERY'> ; QUERY VERIFY SWITCH.
  447.     PUSH    AH
  448.     MOV    AH,54H
  449.     INT    21H
  450.     POP    AH
  451. ENDIF
  452.     ENDM
  453.  
  454. ;;-----------------------------------------------------------------------
  455. ;;
  456. ;; GETDTA - Get DTA (Data Transfer Area).  On return - ES:BX has address
  457. ;;        of DTA.
  458. ;;
  459. ;;-----------------------------------------------------------------------
  460. GETDTA    MACRO            ; Get address of DTA.
  461.     PUSH    AH
  462.     MOV    AH,2FH
  463.     INT    21H
  464.     POP    AH
  465.     ENDM
  466.  
  467. ;;-----------------------------------------------------------------------
  468. ;;
  469. ;; VERSION - Get PC-DOS version number.
  470. ;;
  471. ;;  OUTPUT:  AL = major version number,
  472. ;;         AH = minor version number.
  473. ;;         If AL = 0 then assume pre DOS 2.0
  474. ;;
  475. ;;-----------------------------------------------------------------------
  476. VERSION MACRO            ; Get PC-DOS version number.
  477.     MOV    AH,30H
  478.     INT    21H
  479.     ENDM
  480.  
  481. ;;-----------------------------------------------------------------------
  482. ;;
  483. ;; KEEP <rc>,<beg>,<fin> - Terminate this program but stay resident.
  484. ;;
  485. ;;    <rc>  = The return code for this program.
  486. ;;    <beg> = The begining address of the program.
  487. ;;    <fin> = The last byte plus one used by the program.
  488. ;;        This number is divided by 16 to determine the memory
  489. ;;        size in paragraphs required.
  490. ;;    Registers may not be passed for <beg> and <fin>.
  491. ;;
  492. ;;-----------------------------------------------------------------------
  493. KEEP    MACRO RC,BEG,FIN
  494.     MOV    AL,RC
  495.     MOV    DX,(FIN-BEG)/16
  496.     MOV    AH,31H
  497.     INT    21H
  498.     ENDM
  499.  
  500. ;;-----------------------------------------------------------------------
  501. ;;
  502. ;; CTL_BRK <flag> - Read or write the current CTL-BRK state.
  503. ;;
  504. ;;       <flag> - Is either 'ON', 'OFF' or not specified.
  505. ;;
  506. ;;       If flag is not specified then current CTL-BRK state is
  507. ;;       returned in DL.
  508. ;;
  509. ;;       All registers saved if <flag> is specified elss DL is destroyed.
  510. ;;
  511. ;;-----------------------------------------------------------------------
  512. CTL_BRK MACRO    FLAG        ; R/W  CTRL-BREAK status flag.
  513.     PUSH    AX
  514.     MOV    AH,33H
  515. IFB    <FLAG>
  516.     XOR    AL,AL
  517. ELSE
  518.     MOV    AL,1
  519. ENDIF
  520. IFNB
  521.   IFIDN   <FLAG>,<'OFF'>
  522.       XOR      DL,DL
  523.   ENDIF
  524.   IFIDN   <FLAG>,<'ON'>
  525.       MOV      DL,1
  526.   ENDIF
  527. ENDIF
  528.     INIT    21H
  529.     POP    AX
  530.     ENDM
  531.  
  532. ;;-----------------------------------------------------------------------
  533. ;;
  534. ;; DISKAVAIL <DRIVE>
  535. ;;
  536. ;;-----------------------------------------------------------------------
  537.  
  538. ;;-----------------------------------------------------------------------
  539. ;;
  540. ;;
  541. ;;
  542. ;;-----------------------------------------------------------------------
  543.  
  544. ;;-----------------------------------------------------------------------
  545. ;;
  546. ;;
  547. ;;
  548. ;;-----------------------------------------------------------------------
  549.  
  550. ;;-----------------------------------------------------------------------
  551. ;;
  552. ;;
  553. ;;
  554. ;;-----------------------------------------------------------------------
  555.  
  556. ;;-----------------------------------------------------------------------
  557. ;;
  558. ;;
  559. ;;
  560. ;;-----------------------------------------------------------------------
  561.  
  562. ;;-----------------------------------------------------------------------
  563. ;;
  564. ;;
  565. ;;
  566. ;;-----------------------------------------------------------------------
  567.  
  568. ;;-----------------------------------------------------------------------
  569. ;;
  570. ;;
  571. ;;
  572. ;;-----------------------------------------------------------------------
  573.  
  574. ;;-----------------------------------------------------------------------
  575. ;;
  576. ;;
  577. ;;
  578. ;;-----------------------------------------------------------------------
  579.  
  580. ;;-----------------------------------------------------------------------
  581. ;;
  582. ;;
  583. ;;
  584. ;;-----------------------------------------------------------------------
  585.  
  586. ;;-----------------------------------------------------------------------
  587. ;;
  588. ;;
  589. ;;
  590. ;;-----------------------------------------------------------------------
  591.  
  592. ;;;;;; test prog
  593.     assume cs:cseg,ds:cseg,es:cseg
  594. cseg    segment para 'code'
  595. x    proc    far
  596.     push    ds
  597.     xor    ax,ax
  598.     push    ax
  599.  
  600.     writeln 'a message'     ;; test writeln, save, restore.
  601.  
  602.     ret
  603. x    endp
  604. cseg    ends
  605.     end
  606.  
  607.